import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'
import { resolve } from 'path';
function pathResolve(dir) {
  return resolve(__dirname, dir);
}
// https://vitejs.dev/config/
export default defineConfig({
  base:'./',
  envDir: './config',
  envPrefix: 'YY_', // 以 YY_ 开头的环境变量会通过 import.meta.env 暴露
  plugins: [
    vue(),
    PkgConfig(),
    OptimizationPersist(),
    Components({
      resolvers: [AntDesignVueResolver({
        importStyle: 'less'
      })]
    }),
  ],
  server: {
    port: 6600,
    open: true,
    // 使用以下地址http://127.0.0.1:6600/yueyin-test代替http://127.0.0.1:6700的网址,
    //这样可以避免被人知道后端接口地址是什么.这样如果前端关闭代理之后,那么http://127.0.0.1:6600/yueyin-test将
    //不能使用,但是真实的服务器端地址:http://127.0.0.1:6700还能使用.
    proxy: {
      '/yueyin-test':{
        target: 'http://127.0.0.1:6700',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/yueyin-test/, '')
      },
    }
  },
  //对阿里云的一些配置
  resolve: {
    alias: {
      '@': pathResolve('src'),
    },
    extensions: [".js", ".ts", ".tsx", ".jsx"]
  },
  //对less进行的一些配置
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          'primary-color': '#2288fe',
          'border-color-base':'#e3e8f0'
        },
        additionalData:  `@import "${pathResolve('src/styles/variable.less')}";`,
        javascriptEnabled: true
      }
    }
  },
  
})
